import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
import { type PageLayoutTabEntity } from 'src/engine/metadata-modules/page-layout/entities/page-layout-tab.entity';

export const transformPageLayoutTabEntityToFlatPageLayoutTab = (
  pageLayoutTabEntity: PageLayoutTabEntity,
): FlatPageLayoutTab => {
  return {
    createdAt: pageLayoutTabEntity.createdAt,
    deletedAt: pageLayoutTabEntity.deletedAt,
    updatedAt: pageLayoutTabEntity.updatedAt,
    id: pageLayoutTabEntity.id,
    title: pageLayoutTabEntity.title,
    position: pageLayoutTabEntity.position,
    pageLayoutId: pageLayoutTabEntity.pageLayoutId,
    workspaceId: pageLayoutTabEntity.workspaceId,
    universalIdentifier:
      pageLayoutTabEntity.universalIdentifier ?? pageLayoutTabEntity.id,
    applicationId: pageLayoutTabEntity.applicationId,
    widgetIds: pageLayoutTabEntity.widgets.map((widget) => widget.id),
  };
};
